home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / pvm34b3.zip / pvm34b3 / pvm3 / examples / rme.c < prev    next >
C/C++ Source or Header  |  1997-07-22  |  4KB  |  132 lines

  1.  
  2. static char rcsid[] =
  3.     "$Id: rme.c,v 1.4 1997/07/09 13:25:17 pvmsrc Exp $";
  4.  
  5. /*
  6.  *         PVM version 3.4:  Parallel Virtual Machine System
  7.  *               University of Tennessee, Knoxville TN.
  8.  *           Oak Ridge National Laboratory, Oak Ridge TN.
  9.  *                   Emory University, Atlanta GA.
  10.  *      Authors:  J. J. Dongarra, G. E. Fagg, M. Fischer
  11.  *          G. A. Geist, J. A. Kohl, R. J. Manchek, P. Mucci,
  12.  *         P. M. Papadopoulos, S. L. Scott, and V. S. Sunderam
  13.  *                   (C) 1997 All Rights Reserved
  14.  *
  15.  *                              NOTICE
  16.  *
  17.  * Permission to use, copy, modify, and distribute this software and
  18.  * its documentation for any purpose and without fee is hereby granted
  19.  * provided that the above copyright notice appear in all copies and
  20.  * that both the copyright notice and this permission notice appear in
  21.  * supporting documentation.
  22.  *
  23.  * Neither the Institutions (Emory University, Oak Ridge National
  24.  * Laboratory, and University of Tennessee) nor the Authors make any
  25.  * representations about the suitability of this software for any
  26.  * purpose.  This software is provided ``as is'' without express or
  27.  * implied warranty.
  28.  *
  29.  * PVM version 3 was funded in part by the U.S. Department of Energy,
  30.  * the National Science Foundation and the State of Tennessee.
  31.  */
  32.  
  33. /*
  34.  *    Filename:     rme.c        ( remove mailbox entry )
  35.  *
  36.  *  This program will seek out a "well known" service from a mailbox
  37.  *  and then remove it.
  38.  *
  39.  *  Don't bother with flags here as they are not used by pvm_delinfo()
  40.  *
  41.  *    usage: rme [service_name] [index_nbr]
  42.  *
  43.  *  Note: If a task is waiting for someone to communicate via mailbox
  44.  *    information will be left stranded after this program removes 
  45.  *    the associated entry from the mailbox database.
  46.  *
  47.  *  files used:  rme.c taskf.c
  48.  */
  49.  
  50. #include <stdio.h>
  51. #ifndef WIN32
  52. #include <unistd.h>        /* for gethostname */
  53. #else
  54. #include "pvmwin.h"
  55. #endif
  56. #include "pvm3.h"
  57.  
  58. main( argc, argv )
  59. int argc;
  60. char *argv[];
  61. {
  62.     char *me = "rme";
  63.     char machine[25];
  64.     int mytid;
  65.     int info;
  66.     int index;                 /* index of the service seeking */
  67.     char *service_name;        /* name of the service seeking */
  68.  
  69.     /* display_incomming_parameters( me, argc, argv ); */
  70.  
  71.     printf( "\n" );
  72.     if ( argc != 3 ) {
  73.         printf( "\nusage: task_end [service_name] [index_nbr]\n" );
  74.         exit( -1 );
  75.     }
  76.  
  77.     index = atoi( argv[2] );
  78.     service_name = argv[1];
  79.     printf( "Looking for service name <%s> with index number [%d].\n",
  80.             service_name, index );
  81.  
  82.     if ( ( mytid = pvm_mytid() ) == PvmSysErr ) {
  83.         printf( "\nPVM not up!\n" );
  84.         exit( -1 );
  85.     }
  86.  
  87.     gethostname( machine, 25 );
  88.  
  89.     printf( "%s: t%x on machine <%s> with context %d.\n",
  90.             me, mytid, machine, pvm_getcontext() );
  91.  
  92.     /*
  93.      *  attempt to delete the ( service_name, index ) pair from the
  94.      *  mailbox
  95.      */
  96.     if ( (info = pvm_delinfo( service_name, index, PvmMboxDefault ))
  97.             < 0 ) {
  98.         /*
  99.          *  did not find mailbox - tell user why and exit...
  100.          */
  101.         switch ( info )
  102.         {
  103.             case PvmNotFound:
  104.                 printf(
  105.                     "\n%s: no service running for <%s> index <%d>\n",
  106.                         me, service_name, index );
  107.                 break;
  108.             case PvmBadParam:
  109.                 printf( "\n%s: Invalid argument to pvm_recvinfo().\n",
  110.                         me );
  111.                 break;
  112.             case PvmNoSuchBuf:
  113.                 printf( "\n%s: Message buffer id does not exist.\n",
  114.                         me );
  115.                 break;
  116.             case PvmDenied:
  117.                 printf(
  118.                     "\n%s: Key locked by another task, can't delete.\n",
  119.                         me );
  120.                 break;
  121.             default:
  122.                 lpvmerr( "\n%s: rme.c: error %d", me, info );
  123.                 break;
  124.         } /* end_switch */
  125.         exit( -1 );
  126.     } /* end_if */
  127.  
  128.     pvm_exit();
  129.     exit( 0 );
  130. }
  131.  
  132.